package com.jiuyuan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jiuyuan.entity.AdminRole;
import com.jiuyuan.entity.vo.RespBean;
import com.jiuyuan.mapper.AdminRoleMapper;
import com.jiuyuan.service.IAdminRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiuyuan
 * @since 2023-02-15
 */
@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements IAdminRoleService {
    @Autowired
    AdminRoleMapper adminRoleMapper;

    @Override
    @Transactional
    public RespBean updateRoles(Integer adminId, Integer[] roleIds) {
        adminRoleMapper.delete(new QueryWrapper<AdminRole>().eq("adminId",adminId));
        if(null==roleIds||0==roleIds.length)
            return RespBean.success("更新成功");
        int reslt = adminRoleMapper.add(adminId,roleIds);
        if(reslt == roleIds.length) return RespBean.success("更新成功");
        return RespBean.error("更新失败");
    }
}
